package com.nuanshui.heatedloan.module.facade;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.Maps;
import com.nuanshui.heatedloan.module.model.ModuleForm;
import com.nuanshui.framework.springContext.SpringContextUtil;

public class ModuleBuilderFactory {
	private static List<String> fakeModuleName = Arrays.asList();
	private static Map<String, IModuleBuilder> classMap = Maps.newLinkedHashMap();


	public static IModuleBuilder getModuleBuilderFactory(ModuleForm form) {
		IModuleBuilder builder;
		if (StringUtils.isNotEmpty(form.getModuleName()) && fakeModuleName.contains(form.getModuleName())) {
			builder = classMap.get("fakeModuleBuilder");
			if (builder == null) {
				builder = SpringContextUtil.getBean("fakeModuleBuilder");
				classMap.put("fakeModuleBuilder", builder);
			}

		} else {
			builder = classMap.get("moduleBuilder");
			if (builder == null) {
				builder = SpringContextUtil.getBean("moduleBuilder");
			}
		}
		return builder;
	}
}
